/*
 * @Author: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @Date: 2025-09-03 01:20:43
 * @LastEditors: 无聊 7989314+Hwz1997@user.noreply.gitee.com
 * @LastEditTime: 2025-09-24 08:43:38
 * @FilePath: \keep_motion_api\controllers\sport\sportActivities.controller.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { SportType } = require('@/models/sport');
const { clearObject } = require('@/utils');
// 查询运动类型
const getSportType = async (req, res) => {
  try {
    const { name, pageNum, pageSize } = req.query;
    const offset = (pageNum - 1) * pageSize;
    const limit = pageSize;
    const {rows, total} = await SportType.getSportType(name, offset, limit);
    res.status(200).send({rows, total});
  } catch (error) {
    res.status(500).json({ message: '查询运动类型失败', error });
  }
}
const createSportType = async (req, res) => {
  try {
    const body = req.body;
    const params = clearObject(body);
    const sportType = await SportType.createSportType(params);
    res.status(200).send(sportType);
  } catch (error) {
    res.status(500).json({ message: '创建运动类型失败', error });
  }
}
const updateSportType = async (req, res) => {
  try {
    const { id } = req.params;
    const body = req.body;
    const params = clearObject(body);
    const sportType = await SportType.updateSportType(id, params);
    res.status(200).send(sportType);
  } catch (error) {
    res.status(500).json({ message: '更新运动类型失败', error });
  }
}
const deleteSportType = async (req, res) => {
  try {
    const { id } = req.params;
    const sportType = await SportType.deleteSportType(id);
    res.status(200).send(sportType);
  } catch (error) {
    res.status(500).json({ message: '删除运动类型失败', error });
  }
}
module.exports = {
  getSportType,
  createSportType,
  updateSportType,
  deleteSportType
}